/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iftk.xmlparser.domain;

/**
 *
 * @author treiman
 */
public abstract class RSSFeed extends BubbleItem {
    private String title;
    private String contents;
    private String pubDate;

    public String getPubDate() {
        return pubDate;
    }

    public void setPubDate(String pubDate) {
        this.pubDate = pubDate;
    }

    public String getContents() {
        return contents;
    }

    public void setContents(String contents) {
        if(contents.substring(0, 2).equals(", ")) {
            this.contents = contents.substring(2, contents.length());
        }
        else {
            this.contents = contents;
        }
        this.contents = this.contents.replace("&", "&amp;");
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        if(this instanceof DepartmentNews) {
            this.title = title;
        }        
        else {
            String[] tokens = title.split(",");
            this.setPubDate(tokens[0]);
            StringBuilder result = new StringBuilder();
            for(int i = 1; i < tokens.length; i++) {
                result.append(tokens[i]);
            }
            
            String temp = result.toString();
            this.title = temp;
        }
        this.title = this.title.replace("&", "&amp;");
    }
    
    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");
        
        result.append(this.getClass().getName()).append("Object {").append(NEW_LINE);
        result.append(" ID: ").append(getId()).append(NEW_LINE);
        result.append(" Title: ").append(title).append(NEW_LINE);
        result.append(" Description: ").append(contents).append(NEW_LINE);
        result.append("}");
        
        return result.toString();
    }
    
    @Override
    public String toBubble() {
        StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");
        
        result.append("<bubble>").append(NEW_LINE);
        result.append("\t<id>").append(getId()).append("</id>").append(NEW_LINE);
        result.append("\t<titletext>");
        result.append(getPubDate());
        result.append("</titletext>").append(NEW_LINE);
        result.append("\t<titlefontsize>10</titlefontsize>").append(NEW_LINE);
        if(this instanceof DepartmentEvent) {
            result.append("\t<shorttext fontsize=\"4\">").append(title).append("\n").append(contents).append("</shorttext>").append(NEW_LINE);
        }
        else {
            result.append("\t<shorttext fontsize=\"4\">").append(title).append("</shorttext>").append(NEW_LINE);
            result.append("\t<fulltext fontsize=\"3\">").append(contents).append("</fulltext>").append(NEW_LINE);            
        }
        if(this instanceof DepartmentNews) {
            result.append("\t<style>Yellow</style>").append(NEW_LINE);
        }
        else {
            result.append("\t<style>WhiteLevel3</style>").append(NEW_LINE);
        }

        result.append("\t<links></links>").append(NEW_LINE);
        result.append(("\t<priority>3</priority>")).append(NEW_LINE);
        result.append("</bubble>").append(NEW_LINE);
        
        return result.toString();
    }
    
}
